﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CsharpCodeGenerator
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            ConfigTemplate ct = Configuration.ReadConfig();

            ct.AuthorName = Authorname.Text;
            ct.PassNullAsDefaultParamaeterValue = AllowNulls.Checked;
            ct.GenerateWrapperClass = Wrapper.Checked;
            ct.WrapperClass_GenerateStaticMethods = IsStatic.Checked;
            ct.GenerateDeleteRowProc = Delete.Checked;
            ct.GenerateInsertProc = Insert.Checked;
            ct.GenerateSelectAllProc = All.Checked;
            ct.GenerateSelectRowProc = Specify.Checked;
            ct.GenerateUpdateProc = Update.Checked;
            ct.GenerateSelectRowByForeignKeyProc = ForeignKey.Checked;
            ct.SaveToFile = ckSave.Checked;
            ct.Namespace = txtNamespace.Text;

            ct.GenEntity = IsGenEntity.Checked;

            Configuration.WriteConfig(ct);
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
            
        }

        private void OK_Click(object sender, EventArgs e)
        {
            ConfigTemplate ct = Configuration.ReadConfig();

            ct.AuthorName = Authorname.Text;
            ct.PassNullAsDefaultParamaeterValue = AllowNulls.Checked;
            ct.GenerateWrapperClass = Wrapper.Checked;
            ct.WrapperClass_GenerateStaticMethods = IsStatic.Checked;
            ct.GenerateDeleteRowProc = Delete.Checked;
            ct.GenerateInsertProc = Insert.Checked;
            ct.GenerateSelectAllProc = All.Checked;
            ct.GenerateSelectRowProc = Specify.Checked;
            ct.GenerateUpdateProc = Update.Checked;
            ct.GenerateSelectRowByForeignKeyProc = ForeignKey.Checked;
            ct.SaveToFile = ckSave.Checked;
            ct.Namespace = txtNamespace.Text;

            ct.GenEntity = IsGenEntity.Checked;

            Configuration.WriteConfig(ct);

            Close();
        }
    }
}
